package com.winning.pmph.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.winning.pmph.vo.NameSuggestion;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

import javax.persistence.Table;
import java.util.List;

/**
 * @author 刘亚飞
 * @Description
 * @create 2021-03-16 17:39
 */
@Data
@Table(name = "task_item")
public class TaskItem extends BaseEntity {

    private static final long serialVersionUID = 7775229163590542668L;

    /**
     * 未提交
     */
    public final static Integer STATUS_NOT_COMMIT = 0;

    /**
     * 初审中
     */
    public final static Integer STATUS_COMMIT = 1;

    /**
     * 审核通过
     */
    public final static Integer STATUS_PASS = 2;

    /**
     * 初审驳回
     */
    public final static Integer STATUS_REJECT = 3;

    /**
     * 初审通过，复审中
     */
    public final static Integer STATUS_PASS_1 = 4;

    /**
     * 复审驳回
     */
    public final static Integer STATUS_REJECT_2 = 5;

    /**
     * 终审中／复审通过
     */
    public final static Integer STATUS_PASS_2 = 6;

    /**
     * 终审驳回
     */
    public final static Integer STATUS_REJECT_3 = 7;

    /**
     * 发布
     */
    public final static Integer STATUS_RELEASED = 8;

    /** 最终审核通过后驳回 */
    public final static Integer STATUS_FINAL_REJECT = 9;

    /**
     * 逻辑删除标志  未删除
     */
    public static final int NO_DELETED = 0;

    /**
     * 逻辑删除  已删除
     */
    public static final int DELETED = 1;
    /**
     * 类型, 非自建(任务编辑人员创建), 自建(知识编辑人员创建), 修订, 非自建_素材, 修订_素材
     */
    public static final int TYPE_TASK_EDITOR_CREATE = 0;
    public static final int TYPE_KNOWLEDGE_EDITOR_CREATE = 1;
    public static final int TYPE_EDIT = 2;
    public static final int TYPE_TASK_EDITOR_CREATE_KNOWLEDGE_UNIT = 3;
    public static final int TYPE_EDIT_KNOWLEDGE_UNIT = 4;

    /**
     * ID
     */
    @TableId
    private String id;
    /**
     * 任务ID
     */
    private String taskId;
    /**
     * 知识ID，医学计算器ID，流程图ID
     */
    private String knowledgeId;
    /**
     * 子任务名称
     */
    private String name;
    /**
     * 子任务类型 0非自建 1自建 2修订
     */
    private int type;
    /**
     * 编辑人员
     */
    private String editor;
    /**
     * 初审人员
     */
    private String firstAuditor;
    /**
     * 复审人员
     */
    private String secondAuditor;
    /**
     * 终审人员
     */
    private String thirdAuditor;
    /**
     * 审核状态 0：未提交，1：初审中，2：审核通过／未发布，3：初审驳回 4：初审通过，复审中
     * ５：复审驳回  ６：终审中／复审通过  7：终审驳回  8：已发布
     */
    private int status;
    /**
     * 删除  0 未删除 1 删除
     */
    private int deleted;
    /**
     * 备注
     */
    private String remark;
    
    private int wordsCount;
    /**
     * 任务提交时间
     *
     * <p>时间格式：yyyy-MM-dd</p>
     */
    private String submitTime;
    
    // 当前操作人, 冗余字段, 简化查询;
    private String crtOperator;
    // 关联疾病, 冗余字段, 简化查询,只有健康问答库使用;
    private String relationDisease;
    private String reject;
    // 名称修改意见;
    private NameSuggestion nameSuggestion;
    // 是否催办;
    private boolean press;
    @TableField(exist = false)
    private String startDate;
    @TableField(exist = false)
    private String endDate;
    @TableField(exist = false)
    private String knowledgeLibId;
    @TableField(exist = false)
    private String knowledgeLibName;
    @TableField(exist = false)
    private int num;
    @TableField(exist = false)
    private int enableCreate;
    @TableField(exist = false)
    private String systemType;
    @TableField(exist = false)
    private int auditLevel;
    @TableField(exist = false)
    private String markStatus;
    @TableField(exist = false)
    private List<TaskItem> similarTaskItemList;
    @TableField(exist = false)
    private String drugInfoLibCompany;
    @TableField(exist = false)
    private String drugInfoLibSource;


    public String getCrtOperator() {
        if (status == STATUS_NOT_COMMIT
            || status == STATUS_REJECT) {
            return editor;
        }
        else if (status == STATUS_COMMIT
                || status == STATUS_REJECT_2) {
            return firstAuditor;
        }
        else if (status == STATUS_PASS_1
                || status == STATUS_REJECT_3) {
            return secondAuditor;
        }
        else if (status == STATUS_PASS_2) {
            return thirdAuditor;
        }
        else if (status == STATUS_PASS
                || status == STATUS_RELEASED) {
            return StringUtils.EMPTY;
        }
        else if (status == STATUS_FINAL_REJECT) {
            if (auditLevel == Task.AUDIT_LEVEL_ONE) {
                return firstAuditor;
            }
            else if (auditLevel == Task.AUDIT_LEVEL_TWO) {
                return secondAuditor;
            }
            else if (auditLevel == Task.AUDIT_LEVEL_THREE) {
                return thirdAuditor;
            }
        }
        return crtOperator;
    }
}

